#include "key.h"

static KEY_t my_key = {0,0,0};

void key_scan(void)
{
	my_key.val = !(KEY_GPIO_Port->IDR & KEY_Pin);
	switch(my_key.cnt)
	{
		case first:
			if(my_key.val == 0)my_key.cnt=second;
			break;
		case second:
			(my_key.val==0)?(my_key.cnt=final):(my_key.cnt=first);
			break;
		case thirty:
			(my_key.val==0)?(my_key.cnt=final):(my_key.cnt=first);
			break;
		case final:
			(my_key.val==0)?(my_key.state=release):(my_key.state=press);
			my_key.cnt=first;
			break;
	}
}

KEY_State_t key_getVal(void)
{
	KEY_State_t ret = my_key.state;
	my_key.state = release;
	return ret;
}

